﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UM_SERVER.Command
{
    class CommandProcessRouter
    {
        private List<ICommandListener> listeners;

        public CommandProcessRouter()
        {
            listeners = new List<ICommandListener>();
        }

        /// <summary>
        ///     安装命令监听器
        /// </summary>
        /// <param name="commandlistener" type="UM_SERVER.Command.ICommandListener">
        ///     <para>
        ///         命令监听器
        ///     </para>
        /// </param>
        /// <returns>
        ///     返回true, 安装成功
        /// </returns>
        public bool InstallCommandListener(ICommandListener commandlistener)
        {
            listeners.Add(commandlistener);
            return true;
        }

        public void ProcessCommand(Command command)
        {
            foreach (ICommandListener listener in listeners)
            {
                if (listener.Accpet(command))
                {
                    listener.ProcessCommand(command);
                    break;
                }
            }
        }
    }
}
